package com.usian.controller;

import com.usian.pojo.Number;
import com.usian.service.NumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;

import java.io.IOException;

@Controller
@RequestMapping("/nu")
public class LoginController {

    @Autowired
    private NumberService numberService;

    @RequestMapping("/Login")
    public String Login(){
        return "login";
    }

    @RequestMapping("/tologin")
    public String tologin(Number number) throws IOException {
        String name=number.getName();
        Number numbers=numberService.selectByName(name);
        if(numbers!=null){
            if(numbers.getPwd().equals(number.getPwd())){
                if(numbers.getId()==1) {
                    return "redirect:/number/findAll";
                }else if (numbers.getId()==2){
                    return "redirect:/department/findAll";
                }else if(numbers.getId()==3){
                    return "redirect:/job/findAll";
                }
            }
        }
        return "login";
    }
}
